home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / SMALLTAL / SMALLTAL.K_R < prev   
Text File  |  1990-07-16  |  4KB  |  97 lines

  1.  
  2. 'The following source-code implements a modified ChangeListView recover
  3. mechanism which allows you to specify how many snapshots you want to go back.
  4. Despite its simplicity, it has been very useful to us over the years and
  5. should have been made public domain software long ago.
  6.  
  7. Try: "ChangeListView recover"
  8. Have fun, Pieter.
  9. ----------------------cut here--------------------------'!
  10.  
  11. !ChangeList methodsFor: 'private'!
  12.  
  13. find: aString lastMinus: anInteger in: aStream
  14.         "Same as findLast:in: if anInteger would be zero.  This methods assumes
  15.         that streaming forward is more efficient than streaming backward, and
  16.         will therefore go faster with increasing jumpSize. However, if snapshots
  17.         happen to follow each other within jumpSize characters in the changes
  18.         file, it will include more snapshots than specified - P.S. van der Meulen"
  19.  
  20.         | firstChar endPosition position count index lastEnd lastMinus jumpSize |
  21.         jumpSize _ 1000.
  22.         lastMinus _ anInteger.
  23.         lastEnd _ nil.
  24.         firstChar _ aString first.
  25.         aStream setToEnd.
  26.         position _ aStream position.
  27.         [endPosition _ position.
  28.         lastEnd == nil and: [(position _ endPosition - jumpSize max: 0) < endPosition]]
  29.                 whileTrue:
  30.                         [aStream position: position.
  31.                         count _ endPosition - position.
  32.                         [count > 0]
  33.                                 whileTrue:
  34.                                         [count _ count - 1.
  35.                                         aStream next = firstChar
  36.                                                 ifTrue:
  37.                                                         [index _ 2.
  38.                                                         [index <= aString size and: [(aString at: index) = aStream next]]
  39.                                                                 whileTrue: [index _ index + 1].
  40.                                                         index > aString size
  41.                                                                 ifTrue: [lastMinus > 0
  42.                                                                                         ifTrue: [lastMinus _ lastMinus - 1]
  43.                                                                                         ifFalse: [lastEnd _ aStream position]]
  44.                                                                 ifFalse: [aStream position: endPosition - count]]]].
  45.         ^lastEnd! !
  46.  
  47. !ChangeList methodsFor: 'initialize-release'!
  48.  
  49. recover: anInteger file: aFileStream
  50.         "Recover all the changes from a .changes file
  51.         since the <last minus anInteger> snapshots.
  52.         Written by Pieter S. van der Meulen."
  53.         
  54.         | position |
  55.         position _ self find: '
  56.  
  57. ''----SNAPSHOT----'
  58.                                         lastMinus: anInteger
  59.                                         in: aFileStream.
  60.         position isNil
  61.                 ifTrue: [position _ 0].
  62.         aFileStream position: position.
  63.         aFileStream upTo: Character cr.
  64.         self scanFile: aFileStream! !
  65.  
  66. !ChangeListView class methodsFor: 'instance creation'!
  67.  
  68. recoverLastMinus: anInteger
  69.         "Open a view of the current changes file since the <last minus anInteger> snapshot."
  70.         
  71.         self openOn: (ChangeList new recover: anInteger file:
  72.                 ((Smalltalk includesKey: #Filename)
  73.                         ifTrue: [(Filename named: (SourceFiles at: 2) name) readStream] "Version 2.5"
  74.                         ifFalse: [SourceFiles at: 2]))                                                                  "Version 2.3"
  75.  
  76.         "ChangeListView recoverLastMinus: 1"!
  77.  
  78. recover
  79.         "Open a view of the current changes file since the last snapshot, or more
  80.         depending on the users request. Modified by Pieter S. van der Meulen."
  81.         
  82.         self recoverLastMinus:
  83.                 (FillInTheBlank
  84.                         request:
  85. 'From how many snapshots do you want to recover changes?
  86. (Enter 0 for the current changes since the last snapshot.)'
  87.                         initialAnswer: '0') asNumber
  88.  
  89.         "ChangeListView recover"! !
  90.  
  91. '----------------------cut here--------------------------'!
  92. -- 
  93. ---------------------------------------------
  94. P.S. van der Meulen, MS 02        prls!pieter
  95. PRLS, Signetics div. of NAPC      -----------
  96. 811 E.Arques Avenue, Sunnyvale, CA 94088-3409
  97.